package leetcode;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by Ghost on 2014/10/10 0010.
 */
public class Populating_Next_Right_Pointers_in_Each_Node_II {
    public void connect(TreeLinkNode root) {
        if(root==null)
            return ;
        TreeLinkNode cur = root;
        Queue<TreeLinkNode> queue = new LinkedList<TreeLinkNode>();
        queue.add(root);
        int size = 0;
        while(!queue.isEmpty()){
            if(size==0)
                size = queue.size();
            cur = queue.poll();
            if(cur.left!=null)
                queue.add(cur.left);
            if(cur.right!=null)
                queue.add(cur.right);
            size--;
            if(size==0){
                cur.next = null;
            }

            else{
                cur.next = queue.peek();
            }
        }
    }
    public static void main(String[] args){
        /*TreeLinkNode root = new TreeLinkNode(1);
        root.left = new TreeLinkNode(2);
        root.right = new TreeLinkNode(3);
        root.left.left = new TreeLinkNode(4);
        root.left.right = new TreeLinkNode(5);
        root.right.left = new TreeLinkNode(6);
        root.right.right = new TreeLinkNode(7);
        Populating_Next_Right_Pointers_in_Each_Node_II populating_next_right_pointers_in_each_node_ii = new Populating_Next_Right_Pointers_in_Each_Node_II();
        populating_next_right_pointers_in_each_node_ii.connect(root);*/
        System.out.println(new BigDecimal(""+0.05).add(new BigDecimal("0.01")).doubleValue());
    }
}
